<template>
  <div class="app-container">
    <el-form  class="formWidth" :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入身份证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否就业" prop="isHired">
        <el-select v-model="queryParams.isHired" placeholder="请选择是否就业" clearable size="small">
          <el-option
            v-for="dict in isHiredOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="就业单位名" prop="hiredCompanyName">
        <el-input
          v-model="queryParams.hiredCompanyName"
          placeholder="请输入就业单位名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="单位性质" prop="hiredCompanyType">
        <el-select v-model="queryParams.hiredCompanyType" placeholder="请选择单位性质" clearable size="small">
          <el-option
            v-for="dict in hiredCompanyTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="职务岗位" prop="hiredPositionName">
        <el-input
          v-model="queryParams.hiredPositionName"
          placeholder="请输入职务岗位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="就业年收入(元)" prop="hiredSalaryNumber">
        <el-input
          v-model="queryParams.hiredSalaryNumber"
          placeholder="请输入就业年收入(元)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="是否创业" prop="isVenture">
        <el-select v-model="queryParams.isVenture" placeholder="请选择是否创业" clearable size="small">
          <el-option
            v-for="dict in isVentureOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="创业公司名称" prop="ventureCompanyName">
        <el-input
          v-model="queryParams.ventureCompanyName"
          placeholder="请输入创业公司名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司创建时间" prop="ventureEstablishTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.ventureEstablishTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择公司创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="公司营业额" prop="ventureTurnover">
        <el-input
          v-model="queryParams.ventureTurnover"
          placeholder="请输入公司营业额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="吸纳就业人数" prop="ventureJobNumber">
        <el-input
          v-model="queryParams.ventureJobNumber"
          placeholder="请输入吸纳就业人数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否愿意培训" prop="isWillTraining">
        <el-select v-model="queryParams.isWillTraining" placeholder="请选择是否愿意培训" clearable size="small">
          <el-option
            v-for="dict in isWillTrainingOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="parseInt(dict.dictValue)"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['jobservice:job:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['jobservice:job:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['jobservice:job:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['jobservice:job:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="jobList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="记录ID" align="center" prop="id" /> -->
      <!-- <el-table-column label="军人id" align="center" prop="soldierId" /> -->
      <el-table-column label="姓名" show-overflow-tooltip align="center" prop="name" />
      <el-table-column label="身份证号"  show-overflow-tooltip align="center" prop="idNumber">
        <template slot-scope="scope">{{scope.row.idNumber? scope.row.idNumber.replace(/^(.{6})(?:\w+)(.{4})$/, "\$1********\$2"):""}}</template>
      </el-table-column>
      <el-table-column label="是否就业" show-overflow-tooltip align="center" prop="isHired" :formatter="isHiredFormat" />
      <el-table-column label="就业单位名" show-overflow-tooltip align="center" prop="hiredCompanyName" />
      <!-- <el-table-column label="单位性质" align="center" prop="hiredCompanyType" :formatter="hiredCompanyTypeFormat" />
      <el-table-column label="职务岗位" align="center" prop="hiredPositionName" />
      <el-table-column label="就业年收入(元)" align="center" prop="hiredSalaryNumber" /> -->
      <el-table-column label="是否创业"  show-overflow-tooltip align="center" prop="isVenture" :formatter="isVentureFormat" />
      <!--<el-table-column label="创业公司名称" align="center" prop="ventureCompanyName" />
      <el-table-column label="公司创建时间" align="center" prop="ventureEstablishTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ventureEstablishTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="公司营业额" align="center" prop="ventureTurnover" />
      <el-table-column label="吸纳就业人数" align="center" prop="ventureJobNumber" />
      <el-table-column label="是否愿意培训" align="center" prop="isWillTraining" :formatter="isWillTrainingFormat" />
      <el-table-column label="培训方向" align="center" prop="trainingDirection" /> -->
      <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['jobservice:job:edit']"
          >修改</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-tickets"
            @click="getInfo(scope.row)"
            v-hasPermi="['jobservice:job:info']"
          >详情</el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['jobservice:job:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改退役军人就业创业信息对话框 -->
    <el-dialog class="addDia" :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-tabs type="border-card" v-model="activeName">
        <el-tab-pane label="基本信息" name="first">
          <el-form ref="userForm" :model="userForm"  label-width="120px" class="formWidth">
            <div class="cardLine">
              <el-row :gutter="20">
                <el-col :span="16">
                  <el-form-item label="身份证号" label-width="250px">
                    <el-select
                      class="cardSearch"
                      v-model="idCard"
                      filterable
                      remote
                      reserve-keyword
                      placeholder="输入身份证号系统自动匹配"
                      :remote-method="remoteMethod"
                      :disabled="isEdit"
                      :loading="idLoading">
                      <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                    <!-- <el-input v-model="idCard" placeholder="输入身份证号系统自动匹配" :readonly="isEdit" /> -->
                  </el-form-item>
                </el-col>
                <el-col :span="4">
                  <el-button type="primary" @click="checkInfo" size="small">查询</el-button>
                </el-col>
              </el-row>
              <!-- <div style="color:red;margin-bottom:10px;padding-left:200px">注：输入身份证号查询【基本信息、参加社会保险情况】</div> -->
            </div>
              <el-col :span="12" >
                <el-form-item label="姓名" prop="name">
                  <el-input class="formWidth" v-model="userForm.name"  readonly/>
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="民族：" prop="nationality">
                  <el-input class="formWidth" v-model="userForm.nationality"  readonly/>
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="性别" prop="sexStr">
                  <el-input class="formWidth" v-model="userForm.sexStr"  readonly/>
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="出生日期" prop="birthDate">
                  <el-date-picker clearable size="small" readonly
                                  v-model="userForm.birthDate"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  class="formWidth"
                                 >
                  </el-date-picker>
                </el-form-item>
              </el-col>
           
              <el-col :span="12" >
                <el-form-item label="户籍" prop="addressBirth">
                  <el-input class="formWidth" v-model="userForm.addressBirth"  readonly />
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="家庭住址" prop="addressLiving">
                  <el-input class="formWidth" v-model="userForm.addressLiving"  readonly />
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="入伍时间" prop="enterArmyTime">
                  <el-date-picker clearable size="small"
                  readonly
                                  v-model="userForm.enterArmyTime"
                                  type="date"
                                  class="formWidth"
                                  value-format="yyyy-MM-dd"
                                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="退伍时间" prop="veteransTime">
                  <el-date-picker clearable size="small" readonly
                                  v-model="userForm.veteransTime"
                                  type="date"
                                  class="formWidth"
                                  value-format="yyyy-MM-dd"
                                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="部队代号" prop="originalArmyCode">
                  <el-input class="formWidth" v-model="userForm.originalArmyCode"  readonly/>
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="联系电话" prop="phoneNo">
                  <el-input class="formWidth" v-model="userForm.phoneNo" readonly/>
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="文化程度" prop="educationalLevelStr">
                  <el-input class="formWidth" v-model="userForm.educationalLevelStr" readonly/>
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="婚姻状况 " prop="marryTypeStr">
                  <el-input class="formWidth" v-model="userForm.marryTypeStr" readonly/>
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="政治面貌" prop="politicsStatusStr">
                  <el-input class="formWidth" v-model="userForm.politicsStatusStr" readonly/>
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="是否悬挂光荣牌" prop="hangHonourCardStr" >
                  <el-input class="formWidth" v-model="userForm.hangHonourCardStr" readonly/>
                </el-form-item>
              </el-col>
              <el-col :span="12" > </el-col>
          </el-form>
        </el-tab-pane>
        <!-- <el-tab-pane label="参加社会保险情况" name="second">
          <el-form class="formWidth" ref="insuranceForm" :model="insuranceForm" label-width="120px">
            <el-row :gutter="20" >
              <el-col :span="12" >
                <el-form-item label="住房公积金" prop="houseFundsStr">
                  <el-input v-model="insuranceForm.houseFundsStr"  readonly/>
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="社会救助" prop="socialAssistanceStr">
                  <el-input  v-model="insuranceForm.socialAssistanceStr"  readonly/>
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="养老保险" prop="endowmentInsuranceStr"> 
                  <el-input  v-model="insuranceForm.endowmentInsuranceStr"  readonly/>
                </el-form-item>
              </el-col>
              <el-col :span="12" >
                <el-form-item label="医疗保险" prop="medicalInsuranceStr">
                  <el-input  v-model="insuranceForm.medicalInsuranceStr"  readonly/>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane> -->
        <el-tab-pane label="就业信息" name="third">
          <el-form class="saveForm formWidth" ref="form" :model="form" :rules="rules" label-width="120px">
            <!-- <div class="line">
              <el-row :gutter="20">
                <el-col :span="20">
                  <el-form-item label="身份证号" prop="idcard">
                    <el-input v-model="form.idcard" placeholder="请输入身份证号校验" />
                  </el-form-item>
                </el-col>
                <el-col :span="4">
                  <el-button type="primary">校验</el-button>
                </el-col>
              </el-row>
            </div> -->
            <div class="line">
              <el-row>
                <el-col :span="20">
                  <el-form-item label="是否就业" prop="isHired">
                    <el-select v-model="form.isHired" placeholder="请选择是否就业" @change="changeHired">
                      <el-option
                        v-for="dict in isHiredOptions"
                        :key="dict.dictValue"
                        :label="dict.dictLabel"
                        :value="parseInt(dict.dictValue)"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            <!-- <el-form-item label="军人id" prop="soldierId">
              <el-input v-model="form.soldierId" placeholder="请输入军人id" />
            </el-form-item> -->
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="就业单位名" prop="hiredCompanyName"> 
                  <el-input  v-model="form.hiredCompanyName" placeholder="请输入就业单位名" :disabled="!isHired" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="单位性质" prop="hiredCompanyType">
                  <el-select  v-model="form.hiredCompanyType" placeholder="请选择单位性质" :disabled="!isHired">
                    <el-option
                      v-for="dict in hiredCompanyTypeOptions"
                      :key="dict.dictValue"
                      :label="dict.dictLabel"
                      :value="parseInt(dict.dictValue)"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="职务岗位" prop="hiredPositionName">
                  <el-input  v-model="form.hiredPositionName" placeholder="请输入职务岗位" :disabled="!isHired"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="就业年收入(元)" prop="hiredSalaryNumber">
                  <el-input v-model="form.hiredSalaryNumber" placeholder="请输入就业年收入(元)" :disabled="!isHired"/>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <div class="line">
            <el-row :gutter="20">
                <el-col :span="20">
                  <el-form-item label="是否创业" prop="isVenture">
                    <el-select v-model="form.isVenture" placeholder="请选择是否创业" @change="changeVenture">
                      <el-option
                        v-for="dict in isVentureOptions"
                        :key="dict.dictValue"
                        :label="dict.dictLabel"
                        :value="parseInt(dict.dictValue)"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="12">
                  <el-form-item label="创业公司名称" prop="ventureCompanyName"> 
                    <el-input  v-model="form.ventureCompanyName" placeholder="请输入创业公司名称" :disabled="!isVenture" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="公司创建时间" prop="ventureEstablishTime">
                    <el-date-picker clearable size="small" :disabled="!isVenture"
                      v-model="form.ventureEstablishTime"
                      type="date"
                      value-format="yyyy-MM-dd"
                      placeholder="选择公司创建时间">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="公司营业额" prop="ventureTurnover">
                    <el-input v-model="form.ventureTurnover" placeholder="请输入公司营业额" :disabled="!isVenture"/>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="吸纳就业人数" prop="ventureJobNumber">
                    <el-input  v-model="form.ventureJobNumber" placeholder="请输入吸纳就业人数" :disabled="!isVenture" />
                  </el-form-item>
                </el-col>
              </el-row>
          </div>
          <div>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="是否愿意培训" prop="isWillTraining" >
                  <el-select  v-model="form.isWillTraining" placeholder="请选择是否愿意培训" @change="changeTrain">
                    <el-option
                      v-for="dict in isWillTrainingOptions"
                      :key="dict.dictValue"
                      :label="dict.dictLabel"
                      :value="parseInt(dict.dictValue)"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="培训方向" prop="trainingDirection" >
                  <el-input v-model="form.trainingDirection" type="textarea" placeholder="请输入内容" :disabled="!isTrain" />
                </el-form-item>
              </el-col>
              <!-- <el-col :span="20">
                <el-form-item label="状态">
                  <el-radio-group class="formWidth" v-model="form.status">
                    <el-radio label="1">请选择字典生成</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col> -->
            </el-row>
          </div>  
          </el-form>
        </el-tab-pane>
      </el-tabs>
      
      <div slot="footer" class="dialog-footer" v-if="activeName == 'third'">
        <el-button type="primary" @click="submitForm" >确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listJob, getJob, delJob, addJob, updateJob, exportJob, checkCard } from "@/api/jobservice/job";
import { getBaseInfoByID } from "@/api/manager/retirefm_1";

export default {
  name: "Job",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 退役军人就业创业信息表格数据
      jobList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否就业字典
      isHiredOptions: [],
      // 单位性质字典
      hiredCompanyTypeOptions: [],
      // 是否创业字典
      isVentureOptions: [],
      // 是否愿意培训字典
      isWillTrainingOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        isHired: null,
        hiredCompanyName: null,
        hiredCompanyType: null,
        hiredPositionName: null,
        hiredSalaryNumber: null,
        isVenture: null,
        ventureCompanyName: null,
        ventureEstablishTime: null,
        ventureTurnover: null,
        ventureJobNumber: null,
        isWillTraining: null,
        trainingDirection: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        isHired: [
          { required: true, message: "是否就业不能为空", trigger: "change" }
        ],
        isVenture: [
          { required: true, message: "是否创业不能为空", trigger: "change" }
        ],
        isWillTraining: [
          { required: true, message: "是否愿意培训不能为空", trigger: "change" }
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ],
      },
      idCard: '',
      userForm: {
      },
       // 性别 1：男性 2：女性字典
      sexOptions: [],
       // 文化程度:1博士、2硕士、3大学本科、4专科、5中专、6高中、7初中及以下字典
      educationalLevelOptions: [],
       // 婚姻状况 1未婚、2已婚、3、离婚、4丧偶字典
      marryTypeOptions: [],
       // 政治面貌字典
      politicsStatusOptions: [],
      // 1：是 0：否字典
      hangHonourCardOptions: [],
      insuranceForm: {}, //保险数据
       // 住房公积金字典
      houseFundsOptions: [],
      // 社会救助状况字典
      socialAssistanceOptions: [],
      // 养老保险字典
      endowmentInsuranceOptions: [],
      // 医疗保险字典
      medicalInsuranceOptions: [],
       // 状态字典
      statusOptions: [],
      isVenture: false,
      isHired: false,
      isTrain: false,
      activeName: 'first', // 新增修改的tab名称
      isEdit: false, //身份证号在编辑的时候readonly
       // 身份证列表
      options: [],
      idLoading: false,
    };
  },
  created() {
    this.getList();
    this.getDicts("yes_or_no").then(response => {
      this.isHiredOptions = response.data;
    });
    this.getDicts("s_hired_company_type").then(response => {
      this.hiredCompanyTypeOptions = response.data;
    });
    this.getDicts("yes_or_no").then(response => {
      this.isVentureOptions = response.data;
    });
    this.getDicts("yes_or_no").then(response => {
      this.isWillTrainingOptions = response.data;
    });
    this.getDicts("sys_user_sex").then(response => {
      this.sexOptions = response.data;
    });
    this.getDicts("degree_of_education").then(response => {
      this.educationalLevelOptions = response.data;
    });
    this.getDicts("marry_type").then(response => {
      this.marryTypeOptions = response.data;
    });
    this.getDicts("political_status").then(response => {
      this.politicsStatusOptions = response.data;
    });
    this.getDicts("yes_or_no").then(response => {
      this.hangHonourCardOptions = response.data;
    });
     this.getDicts("have_or_no").then(response => {
      this.houseFundsOptions = response.data;
    });
    this.getDicts("social_assistance").then(response => {
      this.socialAssistanceOptions = response.data;
    });
    this.getDicts("endowment_insurance").then(response => {
      this.endowmentInsuranceOptions = response.data;
    });
    this.getDicts("medical_insurance").then(response => {
      this.medicalInsuranceOptions = response.data;
    });
    this.getDicts("s_company_status").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
     // 通过身份证查询基本信息
    remoteMethod(id) {
      if (id != "") {
        this.idLoading = true;
        let params = {
          idNumber: id,
        };
        this.options = [];
        getBaseInfoByID(params)
          .then((res) => {
            if (res.rows == null || res.rows == undefined) {
              this.options = [];
              return;
            }
            this.options = res.rows.map((item) => {
              return {
                value: item.idNumber,
                label: item.idNumber,
              };
            });
            this.idLoading = false
          })
          this.idLoading = false
          .catch((err) => console.error(err));
      } else {
        this.options = [];
      }
    },
    changeHired(value){
      if(value == 0){
        this.isHired = false;
        this.form.hiredCompanyName = null;
        this.form.hiredCompanyType = null;
        this.form.hiredPositionName = null;
        this.form.hiredSalaryNumber = null;
      }else{
        this.isHired = true;
      }
    },
    changeVenture(value){
      if(value == 0){
        this.isVenture = false;
        this.form.ventureCompanyName = null;
        this.form.ventureEstablishTime = null;
        this.form.ventureTurnover = null;
        this.form.ventureJobNumber = null;
      }else{
        this.isVenture = true;
      }
    },
    changeTrain(value){
      if(value == 0){
        this.isTrain = false;
        this.form.trainingDirection = null;
      }else{
        this.isTrain = true;
      }
    },
    /** 查询退役军人就业创业信息列表 */
    getList() {
      this.loading = true;
      listJob(this.queryParams).then(response => {
        this.jobList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 是否就业字典翻译
    isHiredFormat(row, column) {
      return this.selectDictLabel(this.isHiredOptions, row.isHired);
    },
    // 单位性质字典翻译
    hiredCompanyTypeFormat(row, column) {
      return this.selectDictLabel(this.hiredCompanyTypeOptions, row.hiredCompanyType);
    },
    // 是否创业字典翻译
    isVentureFormat(row, column) {
      return this.selectDictLabel(this.isVentureOptions, row.isVenture);
    },
    // 是否愿意培训字典翻译
    isWillTrainingFormat(row, column) {
      return this.selectDictLabel(this.isWillTrainingOptions, row.isWillTraining);
    },
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    
    // 取消按钮
    cancel() {
      this.open = false;
      this.isVenture = false;
      this.isHired = false;
      this.isTrain = false;
      this.userForm = {};
      this.insuranceForm = {};
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        soldierId: null,
        isHired: null,
        hiredCompanyName: null,
        hiredCompanyType: null,
        hiredPositionName: null,
        hiredSalaryNumber: null,
        isVenture: null,
        ventureCompanyName: null,
        ventureEstablishTime: null,
        ventureTurnover: null,
        ventureJobNumber: null,
        isWillTraining: null,
        trainingDirection: null,
        status: 0,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.userForm = {};
      this.insuranceForm = {};
      this.reset();
      this.activeName = 'first';
      this.idCard = '';
      this.open = true;
      this.isEdit = false
      this.title = "添加就业创业信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.activeName = 'first';
      this.idCard = row.idNumber;
      const id = row.id || this.ids
      this.getBaseInfo(row.idNumber);
      getJob(id).then(response => {
        this.form = response.data;
        this.isHired = this.form.isHired == 1 ? true :false;
        this.isHired = this.form.isVenture == 1 ? true :false;
        this.isTrain = this.form.isWillTraining == 1 ? true :false;
        this.open = true;
        this.isEdit = true;
        this.title = "修改就业创业信息";
      });
    },
    // 通过身份证获取基本信息
    getBaseInfo(idCard){
      this.userForm = {};
      this.insuranceForm = {};
      let params = {
        idNumber: idCard
      }
      checkCard(params).then(response => {
        this.userForm = response.data.soldierBaseInfo;
        this.form.soldierId = this.userForm.id;
        if(response.data.soldierEmploymentInfo){
          this.insuranceForm = response.data.soldierEmploymentInfo
          this.insuranceForm.houseFundsStr = this.batchFormat(this.houseFundsOptions , this.insuranceForm.houseFunds);
          this.insuranceForm.socialAssistanceStr = this.batchFormat(this.socialAssistanceOptions , this.insuranceForm.socialAssistance);
          this.insuranceForm.endowmentInsuranceStr = this.batchFormat(this.endowmentInsuranceOptions , this.insuranceForm.endowmentInsurance);
          this.insuranceForm.medicalInsuranceStr = this.batchFormat(this.medicalInsuranceOptions , this.insuranceForm.medicalInsurance);
        }else{
          this.insuranceForm = {};
        }
      }).catch(error => {
      })
    },
    /** 提交按钮 */
    submitForm() {
      if(!this.form.soldierId){
        this.msgInfo('请先输入身份证查询并关联就业信息')
        return
      }
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateJob(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addJob(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }   
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      // this.$confirm('是否确认删除退役军人就业创业信息编号为"' + ids + '"的数据项?', "警告", {
        this.$confirm('是否确认删除该项数据?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delJob(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有退役军人就业创业信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportJob(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },

    // 身份证校验
    checkInfo(){
      this.form = {};
      this.reset();
      this.userForm = {};
      this.insuranceForm = {};
      if(!this.idCard){
        this.msgInfo("请输入身份证号");
        return
      }
      // var reg =/(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$)/;
      // if(!reg.test(this.idCard)){
      //   this.msgError('请输入正确的身份证号码');
      //   return
      // }
      let params = {
        idNumber: this.idCard
      }
      checkCard(params).then(response => {
        this.userForm = response.data.soldierBaseInfo;
        this.form.soldierId = this.userForm.id;
        if(response.data.soldierEmploymentInfo){
          this.insuranceForm = response.data.soldierEmploymentInfo
          this.insuranceForm.houseFundsStr = this.batchFormat(this.houseFundsOptions , this.insuranceForm.houseFunds);
          this.insuranceForm.socialAssistanceStr = this.batchFormat(this.socialAssistanceOptions , this.insuranceForm.socialAssistance);
          this.insuranceForm.endowmentInsuranceStr = this.batchFormat(this.endowmentInsuranceOptions , this.insuranceForm.endowmentInsurance);
          this.insuranceForm.medicalInsuranceStr = this.batchFormat(this.medicalInsuranceOptions , this.insuranceForm.medicalInsurance);
        }else{
          this.insuranceForm = {};
        }
      }).catch(error => {
      })
    },
    // 是否愿意培训字典翻译
    batchFormat(allArr , val) {
      return this.selectDictLabel(allArr, val);
    },
  }
};
</script>
<style scoped>
.saveForm .line{
  margin: 10px auto;
  border-bottom: 1px #ccc dashed;
}
.cardLine{
  /* margin: 10px auto; */
  margin-bottom: 20px;
  border-bottom: 1px #ccc dashed;
}
.cardLine .cardSearch{
  width: 300px;
}
.cardLine .cardSearch >>> .el-input__inner{
  width: 100%!important;
}
.addDia >>> .el-dialog__body{
  padding: 20px!important;
}
.addDia >>> .el-input__inner{
  height: 30px!important;
  line-height: 30px;
}
.addDia >>> .el-form-item{
  margin-bottom: 20px;
}
.addDia >>> .el-textarea__inner{
  width: 220px !important;
}
</style>
